function checkdata() {
	if (!checkUserName(register.username.value)) return false;
	if (!checkName(register.name.value)) return false;
	if(!checkaddress(register.addr.value)) return false;
	if(!checkAge(register.birth_year.value,register.birth_month.value)) return false;
	if (!checkid(register.id.value)) return false;
	if (!checkphone(register.phone.value)) return false;
	if (!checkPassWord(register.pwd.value)) return false;
	if (!checkPassWord2(register.pwd2.value)) return false;
	return true;
	}

function checkPassWord(pw) {
	if( strlen(register.pwd.value)<3 || strlen(register.pwd.value)>40 ) {
		//alert("\正确地登录密码长度为3～40位，仅可用英文、数字、特殊字符！");
		document.getElementById("passwordErr").innerHTML = "<font color = 'red'>Password's length is 3 to 40！</font>";
		register.password.focus();
		return false;
	}
	if( strlen2(register.pwd.value) ) {
		//alert("\您的密码中包含了非法字符，仅可用英文、数字、特殊字符！");
		document.getElementById("passwordErr").innerHTML = "<font color = 'red'>Password contains illegal characters!</font>";
		register.password.focus();
		return false;
	}
	if( register.pwd.value == register.username.value ) {
		//alert("\用户名和密码不能相同！");
		document.getElementById("passwordErr").innerHTML = "<font color = 'red'>Username and Password cannot be same！</font>";
		register.password.focus();
		return false;
	}
	document.getElementById("passwordErr").innerHTML = "";
	return true;
}

function checkPassWord2(pw2) {
	if( register.pwd2.value =="" ) {
		//alert("\请输入密码确认！");
		document.getElementById("password2Err").innerHTML = "<font color = 'red'>Please input the Confirm Password！</font>";
		register.password2.focus();
		return false;
	}
	if( register.pwd2.value != register.pwd.value ) {
		//alert("\两次密码输入不一致！");
		document.getElementById("password2Err").innerHTML = "<font color = 'red'>Password and Confirm Password must be same！</font>";
		register.password.focus();
		return false;
	}
	document.getElementById("password2Err").innerHTML = "";
	return true;
}

function checkUserName(ssn){
	if( ssn.length<3 || ssn.length>40 ) {
		//alert("\请输入正确的用户名,用户名长度为3～40位！");
		document.getElementById("usernameErr").innerHTML = "<font color = 'red'>Username's length is 3 to 40！</font>";
		register.username.focus();
		return false;
	}
	if (isWhiteWpace(ssn)){
		//alert("\请输入正确的用户名,用户名中不能包含空格！");
		document.getElementById("usernameErr").innerHTML = "<font color = 'red'>Username cannot contains space！</font>";
		register.username.focus();
		return false;
	}
	if (!isSsnString(ssn)){
		//alert("\对不起，您选择的用户名不正确！用户名\n由a～z的英文字母(不区分大小写)、0～9的数字、点、减\n号或下划线组成，长度为3～40个字符，只能以数字或字母\n开头和结尾,例如：beijing2008，beijing.2008。");
		document.getElementById("usernameErr").innerHTML = "<font color = 'red'>Username contains illegal characters！</font>";
		register.username.focus();
		return false;
	}
	document.getElementById("usernameErr").innerHTML = "";
	return true;
}

function checkName(sn){
	if( sn.length<3 || sn.length>40 ) {
		//alert("\请输入正确的名字,名字长度为3～40位！");
		document.getElementById("nameErr").innerHTML = "<font color = 'red'>Name's length is 3 to 40！</font>";
		register.name.focus();
		return false;
	}
	/*
	if (isWhiteWpace(sn)){
		alert("\请输入正确的名字,名字中不能包含空格！");
		register.name.focus();
		return false;
		}
	if (!isSsnString(sn)){
		alert("\对不起，您选择的名字不正确！名字\n由a～z的英文字母(不区分大小写)、0～9的数字、点、减\n号或下划线组成，长度为3～40个字符，只能以数字或字母\n开头和结尾,例如：beijing2008，beijing.2008。");
		register.name.focus();
		return false;
		}
	*/	
	document.getElementById("nameErr").innerHTML = "";
	return true;
	}

function checkid(userid){
	if( userid.length != 8) {
		//alert("\请输入正确的id,id长度为8位！");
		document.getElementById("idErr").innerHTML = "<font color = 'red'>id's length must be 8！</font>";
		register.id.focus();
		return false;
	}
	if (isWhiteWpace(userid)){
		//alert("\请输入正确的id,id中不能包含空格！");
		document.getElementById("idErr").innerHTML = "<font color = 'red'>id cannot contains space！</font>";
		register.id.focus();
		return false;
	}
	for(a = 0;a<userid.length;a++) {
		if(userid.charAt(a) > '9' || userid.charAt(a) <'0' ) {
			//alert("\请输入正确的id,id中只能為數字！");
			document.getElementById("idErr").innerHTML = "<font color = 'red'>id must be number！</font>";
			register.id.focus();
			return false;
		}
	}
	document.getElementById("idErr").innerHTML = "";
	return true;
}

function checkAge(year,month){ 
	optionclean(document.register.birth_day);
	switch (month) {
	case '2' :  if(checkLeapYear(year)) {
					  document.register.birth_day.options.add(new Option(29));
					 //document.getElementById("birthErr").innerHTML = "<font color = 'red'>該年2月只有29天！</font>";
			  	} 
				break;
	case '4' :
	case '6' :
	case '9' :
	case '11': 	document.register.birth_day.options.add(new Option(29));
				//document.getElementById("birthErr").innerHTML = "<font color = 'red'>該月只有30天！</font>";
				document.register.birth_day.options.add(new Option(30));
				break;
	default : 	document.register.birth_day.options.add(new Option(29));
				document.register.birth_day.options.add(new Option(30));
				document.register.birth_day.options.add(new Option(31));
	}
	//document.getElementById("birthErr").innerHTML = "";
	return true;
}
	
function checkphone(pphone){
	if( pphone.length != 8) {
		//alert("\请输入正确的phone,phone长度为8位！");
		document.getElementById("phoneErr").innerHTML = "<font color = 'red'>Phone's length must be 8！</font>";
		register.phone.focus();
		return false;
	}
	if (isWhiteWpace(pphone)){
		//alert("\请输入正确的phone,phone中不能包含空格！");
		document.getElementById("phoneErr").innerHTML = "<font color = 'red'>Phone cannot contains space！</font>";
		register.phone.focus();
		return false;
	}
	for(b = 0;b<pphone.length;b++) {
		if(pphone.charAt(b) > '9' || pphone.charAt(b) <'0' ) {
			//alert("\请输入正确的phone,phone中只能為數字！");
			document.getElementById("phoneErr").innerHTML = "<font color = 'red'>Phone must be number！</font>";
			register.phone.focus();
			return false;
		}
	}
	document.getElementById("phoneErr").innerHTML = "";
	return true;
}

function checkaddress(address){
	if( address.length<3 || address.length>40 ) {
		//alert("\请输入正确的Address,Address长度为3～40位！");
		document.getElementById("addressErr").innerHTML = "<font color = 'red'>Address's length is 3 to 40！</font>";
		register.addr.focus();
		return false;
	}
	if (isWhiteWpace(address)){
		//alert("\请输入正确的Address,Address中不能包含空格！");
		document.getElementById("addressErr").innerHTML = "<font color = 'red'>Address cannot contains space！</font>";
		register.addr.focus();
		return false;
	}
	if (!isSsnString(address)){
		//alert("\对不起，您选择的Address不正确！用户名\n由a～z的英文字母(不区分大小写)、0～9的数字、点、减\n号或下划线组成，长度为3～40个字符，只能以数字或字母\n开头和结尾,例如：beijing2008，beijing.2008。");
		document.getElementById("addressErr").innerHTML = "<font color = 'red'>Address contains illegal characters!</font>";
		register.addr.focus();
		return false;
	}
	document.getElementById("addressErr").innerHTML = "";
	return true;	
}
	
function strlen(str){
	var len;
	var i;
	len = 0;
	for (i=0;i<str.length;i++){
		if (str.charCodeAt(i)>255) len+=2; else len++;
	}
	return len;
}
	
function strlen2(str){
	var len;
	var i;
	len = 0;
	for (i=0;i<str.length;i++){
		if (str.charCodeAt(i)>255) return true;
	}
	return false;
}

function isWhiteWpace (s) {
	var whitespace = " \t\n\r";
	var i;
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) >= 0) {
			return true;
		}
	}
	return false;
}
	
function isSsnString (ssn) {
	var re=/^[0-9a-z][\w-.]*[0-9a-z]$/i;
	if(re.test(ssn))
		return true;
	else
		return false;
}
	
function checkLeapYear (year) {
	if(year%4 == 0) {
		return true;
	}	
	return false;
}

//清除选项
function optionclean(obj)
{
	obj.options.length=28;
}
	/* function checkssn(gotoURL) {
   	var ssn=register.username.value.toLowerCase();
   	if (checkUserName(ssn)){
	   	var open_url = gotoURL + "?username=" + ssn;
	   	window.open(open_url,'','status=0,directories=0,resizable=0,toolbar=0,location=0,scrollbars=0,width=390,height=260');
		}
	} */
